import useStore from "../store";

export const onShareAppMessage = (from) => {
    // 监听小程序右上角菜单的「转发」按钮
    console.log(wx, 'wx「转发」按钮')
    if (typeof wx === 'undefined') {
        return;
    }

    wx.showShareMenu({
        withShareTicket: true,
        menus: ['shareAppMessage', 'shareTimeline']
    })
    const maxScore = useStore().userStore.userInfo && useStore().userStore.userInfo.maxScore ? useStore().userStore.userInfo.maxScore : 0
    const shareTitleList = [
        '20以内加减法，你能对几个？',
        '20以内加减法，竟然这么难？',
        '不要以为加减法很简单！来试试？',
        '快来测测你的口算能力！',
        '可能这是最好的练口算应用！',
        `游戏结束后分享的文案改为：我得到了${maxScore}分！来试试你能得多少？`
    ]

    const title = maxScore > 0 ? shareTitleList[Math.round(Math.random() * 5)] : shareTitleList[Math.round(Math.random() * 5) - 1]
    console.log(title, 'title')
    // 来自页面内分享按钮
    if (from === 'button') {
        return {
            title: title,
            desc: '简单好玩的加减训练',
            path: '/pages/index/index',
            imageUrl: 'https://file.bendiclass.com/oss/upload/image/png/b080267313e49be9cd9db66a12ee6d46.png'
        }
    }
}
